<?php
// +----------------------------------------------------------------------
// | 用户等级
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
use base\other\Strings;

class UserMemberCard extends Model
{
	use \base\model\ModelTrait;
	
	//事件观察
	protected static function init(){
    	//self::event('after_insert', function ($data) {  });
    }
	
	
	//隐藏字段
	protected $hidden = ["password",'id'];
	
	// 自动完成
	protected $insert = ['code'];
	protected function setCodeAttr() {
		return Strings::createOrderNo();
    }
	
	//关联会员表
	public function userInfo(){
        return $this->hasOne('user','id','bind_uid')->bind([
        	'balance',
        	'balance_gift',
        	'brokerage',
        	'integral'
        ]);
    }
    
    //关联等级表
	public function levelInfo(){
        return $this->hasOne('UserLevel','level','level')->bind([
        	'level_name'=>'name',
        	'role_name',
        	'discounts',
        ]);
    }
    
   	/**
    * 验证规则
    */
	protected $rule = [
		'password|密码'=>'require',
	];
	
		
}
